<?php


namespace 中文汇编器;

require_once "rv32i.class.php";

class 汇编
{
    private $局部标签 = [];
    private $全局标签 = [];
    private $中间代码 = [];
    private $finBinCode = '';

    public function __construct($lLabel, $gLabel, $midCode)
    {
        $this->局部标签 = $lLabel;
        $this->全局标签 = $gLabel;
        $this->中间代码 = $midCode;
        $rv32i = new rv32i($this->局部标签, $this->全局标签);

        foreach ($midCode as $line)
        {
            //由于指令集不仅仅只有rv32i，因此还是需要进行判断再使用相应的指令集汇编
            //var_dump($line);
            //$opItem = mb_split('，', $line["内容"]);
            //var_dump($opItem[0]);
            if ($line["类型"] == '指令')
                $this->finBinCode = $this->finBinCode . $rv32i->合成二进制($line["内容"]);
            else//除了指令以外的字符串、数字等
            {
                //print_r($line);
                $this->finBinCode = $this->finBinCode . $line["内容"];
            }
        }

        //var_dump($this->finBinCode);
        //$f = fopen("test.txt", "w");
        //fwrite($f, $this->finBinCode);
        //return($this->finBinCode);
    }

    public function 获取目标代码()
    {
        return($this->finBinCode);
    }
}